package top.fullj.actor.mq;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

class Subscribers<T> {

    private final List<Action<T>> actions = new CopyOnWriteArrayList<>();

    void add(Action<T> action) {
        actions.add(action);
    }

    void clear() {
        actions.clear();
    }

    boolean remove(Action<T> action) {
        return actions.remove(action);
    }

    void publish(T msg) {
        for (Action<T> action : actions) {
            action.onMessage(msg);
        }
    }

}
